package com.own.center;

import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.own.core.html.form.dateField.DateField;
import com.own.core.html.form.dropDown.DropDown;
import com.own.core.html.form.textField.TextField;
import com.own.core.object.Dao;
import com.own.core.operation.Controller;
import com.own.core.util.OwnDate;

@Entity
@Table(name = "cm_session")
@NamedQueries({ @NamedQuery(name = "session.listByMajor", query = "select s from Session  s " +
		" join s.major m " +
		" where m.id=:id ") })

public class Session extends Dao {
	private long id;

	@TextField(required = true, list = true)
	private String name;

	@TextField(required = true, list = true)
	private String symbol;

	@DateField(list = true)
	private OwnDate examDate;

//	@DropDown()
	private Major major;

	@Id
	@GeneratedValue(strategy = GenerationType.TABLE)
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSymbol() {
		return symbol;
	}

	public void setSymbol(String symbol) {
		this.symbol = symbol;
	}

	@Basic
	@Temporal(TemporalType.DATE)
	public Date getExamDate() {
		return examDate;
	}

	public void setExamDate(Date examDate) {
		if (examDate == null) {
			examDate = null;

		} else {
			this.examDate = new OwnDate(examDate);
		}
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "major_id", nullable = true)
	public Major getMajor() {
		return major;
	}

	public void setMajor(Major major) {
		this.major = major;
	}

}
